package tutor.mina.client;

import java.net.InetSocketAddress;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.mina.common.IoConnector;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketConnector;

public class SynchronousStyleTimeClient {

    static Log log = LogFactory.getLog( SynchronousStyleTimeClient.class );

    public static void main( final String[] args ) {
        final IoConnector connector = new NioSocketConnector();

        connector.getSessionConfig().setUseReadOperation( true );

        connector.getFilterChain().addLast( "codec",
                new ProtocolCodecFilter( new TextLineCodecFactory() ) );

        log.info( connector.connect( new InetSocketAddress( 8150 ) )
                .awaitUninterruptibly().getSession().read()
                .awaitUninterruptibly().getMessage() );

        connector.dispose();
    }

}
